//------------Sonic CD Breakable Wall Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 56: TYPE_BREAKABLEWALL


sub ObjectMain
	if Object.PropertyValue>7
		Object.XPos+=Object.Value0
		Object.YPos+=Object.Value1
		Object.Value1+=16384
		if Object.OutOfBounds==1
			Object.Type=TypeName[BlankObject]
		endif
	endif
endsub


sub ObjectPlayerInteraction
	if Object.PropertyValue<8
		if Player.Animation==10
			PlayerObjectCollision(C_TOUCH,-17,-24,17,24)
			if CheckResult==1
				Object.Type=TypeName[BlankObject]
				PlaySfx(22,0)
				TempValue0=Object.PropertyValue
				TempValue0*=6
				TempValue0+=8
				TempValue1=Object.XPos
				TempValue1-=524288
				TempValue2=Object.XPos
				TempValue2+=524288
				TempValue3=Object.YPos
				TempValue3-=1048576
				if Player.XPos<Object.XPos
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue1,TempValue3)
					Object[TempObjectPos].Value0=-196608
					Object[TempObjectPos].Value1=-131072
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue2,TempValue3)
					Object[TempObjectPos].Value0=-131072
					Object[TempObjectPos].Value1=-131072
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					TempValue3+=1048576
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue1,TempValue3)
					Object[TempObjectPos].Value0=-262144
					Object[TempObjectPos].Value1=-65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue2,TempValue3)
					Object[TempObjectPos].Value0=-196608
					Object[TempObjectPos].Value1=-65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					TempValue3+=1048576
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue1,TempValue3)
					Object[TempObjectPos].Value0=-196608
					Object[TempObjectPos].Value1=65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue2,TempValue3)
					Object[TempObjectPos].Value0=-131072
					Object[TempObjectPos].Value1=65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					TempValue3+=1048576
				else
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue1,TempValue3)
					Object[TempObjectPos].Value0=131072
					Object[TempObjectPos].Value1=-131072
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue2,TempValue3)
					Object[TempObjectPos].Value0=196608
					Object[TempObjectPos].Value1=-131072
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					TempValue3+=1048576
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue1,TempValue3)
					Object[TempObjectPos].Value0=196608
					Object[TempObjectPos].Value1=-65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue2,TempValue3)
					Object[TempObjectPos].Value0=262144
					Object[TempObjectPos].Value1=-65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					TempValue3+=1048576
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue1,TempValue3)
					Object[TempObjectPos].Value0=131072
					Object[TempObjectPos].Value1=65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					CreateTempObject(TypeName[BreakableWall],TempValue0,TempValue2,TempValue3)
					Object[TempObjectPos].Value0=196608
					Object[TempObjectPos].Value1=65536
					Object[TempObjectPos].DrawOrder=4
					TempValue0++
					TempValue3+=1048576
				endif
			endif
		else
			PlayerObjectCollision(C_TOUCH,-17,-24,16,24)
			if CheckResult==1
				if Player.XPos<Object.XPos
					Player.XPos=Player.CollisionLeft
					Player.XPos<<=16
					Player.XPos+=Object.XPos
					Player.XPos-=1048576
					Player.Speed=0
					Player.XVelocity=0
					if Player.Right==1
						if Player.Direction==FACING_RIGHT
							Player.Pushing=2
						endif
					endif
				else
					Player.XPos=Player.CollisionRight
					Player.XPos<<=16
					Player.XPos+=Object.XPos
					Player.XPos+=1048576
					Player.Speed=0
					Player.XVelocity=0
					if Player.Direction==FACING_LEFT
						Player.Pushing=2
					endif
				endif
			endif
		endif
	endif
endsub


sub ObjectDraw
	DrawSprite(Object.PropertyValue)
endsub


sub ObjectStartup
	LoadSpriteSheet("R1/Objects2.gif")
	ArrayPos0=32
	while ArrayPos0<1056
		if Object[ArrayPos0].Type==TypeName[BreakableWall]
			Object[ArrayPos0].DrawOrder=4
		endif
		ArrayPos0++
	loop
	SpriteFrame(-16,-24,32,48,190,1)
	SpriteFrame(-16,-24,32,48,223,1)
	SpriteFrame(-16,-24,32,48,190,50)
	SpriteFrame(-16,-24,32,48,223,50)
	SpriteFrame(-16,-24,32,48,190,99)
	SpriteFrame(-16,-24,32,48,223,99)
	SpriteFrame(-16,-24,32,48,190,148)
	SpriteFrame(-16,-24,32,48,223,148)
	TempValue0=0
	TempValue3=1
	while TempValue0<3
		TempValue1=0
		TempValue2=190
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=1
	while TempValue0<3
		TempValue1=0
		TempValue2=223
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=50
	while TempValue0<3
		TempValue1=0
		TempValue2=190
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=50
	while TempValue0<3
		TempValue1=0
		TempValue2=223
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=99
	while TempValue0<3
		TempValue1=0
		TempValue2=190
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=99
	while TempValue0<3
		TempValue1=0
		TempValue2=223
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=148
	while TempValue0<3
		TempValue1=0
		TempValue2=190
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
	TempValue0=0
	TempValue3=148
	while TempValue0<3
		TempValue1=0
		TempValue2=223
		while TempValue1<2
			SpriteFrame(-8,-8,16,16,TempValue2,TempValue3)
			TempValue1++
			TempValue2+=16
		loop
		TempValue0++
		TempValue3+=16
	loop
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
